package ui.components.ebook
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import utils.DisplayUtil;
	import utils.IClear;

	/**
	 *
	 * 电子书页组件 
	 * @author Raykid
	 * 
	 */
	public class EBookPage extends Sprite implements IClear
	{
		private var _container				: Sprite;
		private var _masker					: Shape;
		
		private var _width					: Number;
		private var _height					: Number;
		
		public function get masker():Shape {
			return _masker;
		}
		
		public function EBookPage(width:Number, height:Number)
		{
			_width = width;
			_height = height;
			super();
			init();
		}
		private function init():void {
			// 内容的容器
			_container = new Sprite();
			addChild(_container);
			// 遮罩
			_masker = new Shape();
			addChild(_masker);
			clear();
			_container.mask = _masker;
		}
		
		public function setSize(width:Number, height:Number, maskLeft:Boolean):void {
			this.visible = (width > 0 && height > 0);
			if(!this.visible) return;
			with(_masker.graphics) {
				clear();
				beginFill(0, 0);
				drawRect(0, 0, width, height);
				endFill();
			}
			if(maskLeft) {
				_masker.x = 0;
				_masker.y = 0;
			} else {
				_masker.x = _width - width;
				_masker.y = 0;
			}
		}
		public function setContent(obj:DisplayObject):void {
			DisplayUtil.removeAllChild(_container);
			DisplayUtil.addChild(obj, _container);
		}
		public function appendContent(obj:DisplayObject):void {
			DisplayUtil.addChild(obj, _container);
		}
		public function clear():void {
			with(_masker.graphics) {
				clear();
				beginFill(0, 0);
				drawRect(-1, -1, 1, 1);
				endFill();
			}
		}
	}
}